<?php
/*由bean脚本生成 powerBy--joe*/
namespace app\common\manage;
use app\common\validate\DistributionValidate;
use app\common\model\DistributionModel;
use app\common\bean\DistributionBean;
use app\common\bean\ListMap;
use app\common\utils\TimeUtil;
use app\common\exception\MyException;
use Exception;
class DistributionManage extends BaseManage
{
	/**
	* @return DistributionManage
	*/
	static function getInstance(){
		return parent::getInstance();
	}


	/**
	 * @desc 获取分页数据
	 * @param ListMap $listMap
	 * @return ListMap $listMap
	 * @throws Exception
	**/
	public function getPaginatorList(ListMap $listMap) {
		$conditionMap = new ListMap();
		$conditionMap->setAlias(DistributionBean::$alias);
		$listMap->setField(DistributionBean::$alias.ALL_FIELD);
		!$this->getParamBool($listMap,"orderFieldName") ?: $conditionMap->setOrder($listMap->getParameter('orderFieldName').SPACE.$listMap->getParameter('orderType'));
		// Todo:添加业务处理代码...
        $conditionMap->setParameter(DistributionBean::$storeId,$listMap->getParameter(DistributionBean::$storeId));
        $conditionMap->setOrder(DistributionBean::$distance);

		//自行选择是连表查询还是单表查询,默认单表
		$resultMap = DistributionModel::getInstance()->getList($conditionMap);
		$resultMap?:MyException::throwMyException("查询数据失败");
		return $resultMap;
	}
	
	/**
	 * @desc 添加数据
	 * @param DistributionBean $distributionBean
	 * @return int int
	 * @throws Exception
	**/
	public function add($distributionBean) {
		//DistributionValidate::getInstance()->goCheck(DistributionValidate::$add,$distributionBean->getData());
		$result = DistributionModel::getInstance()->addDataGetInsertId($distributionBean->getData());
		$result ?: MyException::throwMyException("插入数据失败");
		return $result;
	}
	
	/**
	 * @desc 编辑数据
	 * @param DistributionBean $distributionBean
	 * @return int int
	 * @throws Exception
	**/
	public function edit($distributionBean) {
		DistributionValidate::getInstance()->goCheck(DistributionValidate::$edit,$distributionBean->getData());
		// Todo:添加业务处理代码...


		$result = DistributionModel::getInstance()->updatedData([DistributionBean::$id => $distributionBean->getId()],$distributionBean->getData());
		$result ?: MyException::throwMyException("更新失败");
		return $result;
	}
	
	/**
	 * @desc 删除数据
	 * @param DistributionBean $distributionBean
	 * @return int int
	 * @throws Exception
	**/
	public function delete($distributionBean) {
		//DistributionValidate::getInstance()->goCheck(DistributionValidate::$pkId,$distributionBean->getData());
		// Todo:添加业务处理代码...


		$result = DistributionModel::getInstance()->deleteData([DistributionBean::$id => $distributionBean->getId()]);
		$result ?: MyException::throwMyException("删除失败");
		return $result;
	}
	
	/**
	 * @desc 根据主建获取数据
	 * @param DistributionBean $distributionBean
	 * @return DistributionBean $distributionBean
	 * @throws Exception
	**/
	public function getInfo($distributionBean) {
		DistributionValidate::getInstance()->goCheck(DistributionValidate::$pkId,$distributionBean->getData());
		// Todo:添加业务处理代码...


		$result = DistributionModel::getInstance()->selectData([DistributionBean::$id => $distributionBean->getId()]);
		$result ?: MyException::throwMyException("获取信息失败");
		$distributionBean->setData($result);
		return $distributionBean;
	}
}
